package com.zucai365.football.news;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.zucai365.football.utils.ZuCaiUtils;

public class News163 extends AbstractNews{
	
	public News163( String lianSai,String[] urls ){
		super( lianSai,urls );
	}
	
	@Override
	public List<String> parse() {
		
		StringBuffer html = new StringBuffer();
		
		for( int i=0;i<getUrls().length;i++ ){
			try {
				html.append( ZuCaiUtils.getUrlContent( getUrls()[i] , "gbk" ) );
				Thread.sleep( 2000 );
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
		
		Document doc = Jsoup.parse( html.toString() );
		Elements main = doc.getElementsByClass( "col2" );
		
		Document aDoc = Jsoup.parse( main.toString() );
		Elements aList = aDoc.getElementsByTag( "a" );
		
		for( Element elem : aList ){
			
			//http://sports.163.com/11/1023/16/7H2J71S000051CCL.html==蓝军欲2000万预订巴克利 马塔自称尚难比肩佐拉
			String href = elem.attr( "href" );
			String text = elem.text();
			if( StringUtils.isNotBlank( href ) && href.startsWith( "http://sports.163.com" ) && href.endsWith( "html" ) && text.length() > 3 ){
				System.out.println( href + "=="  + text );
			}
			
		}
		System.out.println( aList.size() );
		return null;
	}
	
	public static void main(String[] args) {
		String[] urls = { "http://sports.163.com/special/m/00051F15/moreycgd.html","http://sports.163.com/special/00051F15/moreycgd_02.html,http://sports.163.com/special/00051F15/moreycgd_03.html","http://sports.163.com/special/00051F15/moreycgd_04.html" };
		AbstractNews news = new News163( "yingchao",urls );
		news.parseUrl();
	}
}
